/**
 * A collection of useful class methods.
 * 
 * @author Casey Marshall (rsdio@metastatic.org)
 */
public class HexUtil
{
	// Constants.
	// -------------------------------------------------------------------------

	static final String HEX = "0123456789abcdef";
	/**
	 * Convert a byte array to a hexadecimal string, as though it were a
	 * big-endian arbitrarily-sized integer.
	 * 
	 * @param buf
	 *            The bytes to format.
	 * @param off
	 *            The offset to start at.
	 * @param len
	 *            The number of bytes to format.
	 * @return A hexadecimal representation of the specified bytes.
	 */
	public static String toHexString(byte[] buf, int off, int len)
	{
		StringBuffer str = new StringBuffer();
		for (int i = 0; i < len; i++)
		{
			str.append(HEX.charAt(buf[i + off] >>> 4 & 0x0F));
			str.append(HEX.charAt(buf[i + off] & 0x0F));
		}
		return str.toString();
	}

	/**
	 * See {@link #toHexString(byte[],int,int)}.
	 */
	public static String toHexString(byte[] buf)
	{
		return toHexString(buf, 0, buf.length);
	}
	
}
